var i;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var c;
var s;
var u;
var _decorator = cc._decorator;
var _ccclass = _decorator.ccclass;
var _property = _decorator.property;
var h = _decorator.disallowMultiple;
var _menu = _decorator.menu;
var _executionOrder = _decorator.executionOrder;
var _ = _decorator.requireComponent;
var ResUtil = require("AA_ResUtil");
var ListItem = require("AA_ListItem");
(function (e) {
  e[e.NODE = 1] = "NODE";
  e[e.PREFAB = 2] = "PREFAB";
})(c || (c = {}));
(function (e) {
  e[e.NORMAL = 1] = "NORMAL";
  e[e.ADHERING = 2] = "ADHERING";
  e[e.PAGE = 3] = "PAGE";
})(s || (s = {}));
(function (e) {
  e[e.NONE = 0] = "NONE";
  e[e.SINGLE = 1] = "SINGLE";
  e[e.MULT = 2] = "MULT";
})(u || (u = {}));
var _def_List = function (e) {
  function _creator() {
    var t = null !== e && e.apply(this, arguments) || this;
    t.templateType = c.NODE;
    t.tmpNode = null;
    t.tmpPrefab = null;
    t._slideMode = s.NORMAL;
    t.pageDistance = .3;
    t.pageChangeEvent = new cc.Component.EventHandler();
    t._virtual = true;
    t.cyclic = false;
    t.lackCenter = false;
    t.lackSlide = false;
    t._updateRate = 0;
    t.frameByFrameRenderNum = 0;
    t.renderEvent = new cc.Component.EventHandler();
    t.selectedMode = u.NONE;
    t.repeatEventSingle = false;
    t.selectedEvent = new cc.Component.EventHandler();
    t._selectedId = -1;
    t._forceUpdate = false;
    t._updateDone = true;
    t._numItems = 0;
    t._inited = false;
    t._needUpdateWidget = false;
    t._aniDelRuning = false;
    t._doneAfterUpdate = false;
    t.adhering = false;
    t._adheringBarrier = false;
    t.curPageNum = 0;
    return t;
  }
  __extends(_creator, e);
  Object.defineProperty(_creator.prototype, "slideMode", {
    get: function () {
      return this._slideMode;
    },
    set: function (e) {
      this._slideMode = e;
    },
    enumerable: false,
    configurable: true
  });
  Object.defineProperty(_creator.prototype, "virtual", {
    get: function () {
      return this._virtual;
    },
    set: function (e) {
      null != e && (this._virtual = e);
      0 != this._numItems && this._onScrolling();
    },
    enumerable: false,
    configurable: true
  });
  Object.defineProperty(_creator.prototype, "updateRate", {
    get: function () {
      return this._updateRate;
    },
    set: function (e) {
      e >= 0 && e <= 6 && (this._updateRate = e);
    },
    enumerable: false,
    configurable: true
  });
  Object.defineProperty(_creator.prototype, "selectedId", {
    get: function () {
      return this._selectedId;
    },
    set: function (e) {
      var t;
      var o = this;
      switch (o.selectedMode) {
        case u.SINGLE:
          if (!o.repeatEventSingle && e == o._selectedId) {
            return;
          }
          t = o.getItemByListId(e);
          var n = undefined;
          if (o._selectedId >= 0) {
            o._lastSelectedId = o._selectedId;
          } else {
            o._lastSelectedId = null;
          }
          o._selectedId = e;
          t && ((n = t.getComponent(ListItem.default)).selected = true);
          if (o._lastSelectedId >= 0 && o._lastSelectedId != o._selectedId) {
            var i = o.getItemByListId(o._lastSelectedId);
            i && (i.getComponent(ListItem.default).selected = false);
          }
          o.selectedEvent && cc.Component.EventHandler.emitEvents([o.selectedEvent], t, e % this._actualNumItems, null == o._lastSelectedId ? null : o._lastSelectedId % this._actualNumItems);
          break;
        case u.MULT:
          if (!(t = o.getItemByListId(e))) {
            return;
          }
          n = t.getComponent(ListItem.default);
          o._selectedId >= 0 && (o._lastSelectedId = o._selectedId);
          o._selectedId = e;
          var a = !n.selected;
          n.selected = a;
          var r = o.multSelected.indexOf(e);
          if (a && r < 0) {
            o.multSelected.push(e);
          } else {
            !a && r >= 0 && o.multSelected.splice(r, 1);
          }
          o.selectedEvent && cc.Component.EventHandler.emitEvents([o.selectedEvent], t, e % this._actualNumItems, null == o._lastSelectedId ? null : o._lastSelectedId % this._actualNumItems, a);
      }
    },
    enumerable: false,
    configurable: true
  });
  Object.defineProperty(_creator.prototype, "numItems", {
    get: function () {
      return this._actualNumItems;
    },
    set: function (e) {
      var t = this;
      if (t.checkInited(false)) {
        if (null == e || e < 0) {
          cc.error("numItems set the wrong::", e);
        } else {
          t._actualNumItems = t._numItems = e;
          t._forceUpdate = true;
          if (t._virtual) {
            t._resizeContent();
            t.cyclic && (t._numItems = t._cyclicNum * t._numItems);
            t._onScrolling();
            t.frameByFrameRenderNum || t.slideMode != s.PAGE || (t.curPageNum = t.nearestListId);
          } else {
            if (t.cyclic) {
              t._resizeContent();
              t._numItems = t._cyclicNum * t._numItems;
            }
            var o = t.content.getComponent(cc.Layout);
            o && (o.enabled = true);
            t._delRedundantItem();
            t.firstListId = 0;
            if (t.frameByFrameRenderNum > 0) {
              var n = t.frameByFrameRenderNum > t._numItems ? t._numItems : t.frameByFrameRenderNum;
              for (var i = 0; i < n; i++) {
                t._createOrUpdateItem2(i);
              }
              if (t.frameByFrameRenderNum < t._numItems) {
                t._updateCounter = t.frameByFrameRenderNum;
                t._updateDone = false;
              }
            } else {
              for (i = 0; i < t._numItems; i++) {
                t._createOrUpdateItem2(i);
              }
              t.displayItemNum = t._numItems;
            }
          }
        }
      }
    },
    enumerable: false,
    configurable: true
  });
  Object.defineProperty(_creator.prototype, "scrollView", {
    get: function () {
      return this._scrollView;
    },
    enumerable: false,
    configurable: true
  });
  _creator.prototype.onLoad = function () {
    this._init();
  };
  _creator.prototype.onDestroy = function () {
    var e = this;
    cc.isValid(e._itemTmp) && e._itemTmp.destroy();
    cc.isValid(e.tmpNode) && e.tmpNode.destroy();
    e._pool && e._pool.clear();
  };
  _creator.prototype.onEnable = function () {
    this._registerEvent();
    this._init();
    if (this._aniDelRuning) {
      this._aniDelRuning = false;
      if (this._aniDelItem) {
        if (this._aniDelBeforePos) {
          this._aniDelItem.position = this._aniDelBeforePos;
          delete this._aniDelBeforePos;
        }
        if (this._aniDelBeforeScale) {
          this._aniDelItem.scale = this._aniDelBeforeScale;
          delete this._aniDelBeforeScale;
        }
        delete this._aniDelItem;
      }
      if (this._aniDelCB) {
        this._aniDelCB();
        delete this._aniDelCB;
      }
    }
  };
  _creator.prototype.onDisable = function () {
    this._unregisterEvent();
  };
  _creator.prototype._registerEvent = function () {
    var e = this;
    e.node.on(cc.Node.EventType.TOUCH_START, e._onTouchStart, e, true);
    e.node.on("touch-up", e._onTouchUp, e);
    e.node.on(cc.Node.EventType.TOUCH_CANCEL, e._onTouchCancelled, e, true);
    e.node.on("scroll-began", e._onScrollBegan, e, true);
    e.node.on("scroll-ended", e._onScrollEnded, e, true);
    e.node.on("scrolling", e._onScrolling, e, true);
    e.node.on(cc.Node.EventType.SIZE_CHANGED, e._onSizeChanged, e);
  };
  _creator.prototype._unregisterEvent = function () {
    var e = this;
    e.node.off(cc.Node.EventType.TOUCH_START, e._onTouchStart, e, true);
    e.node.off("touch-up", e._onTouchUp, e);
    e.node.off(cc.Node.EventType.TOUCH_CANCEL, e._onTouchCancelled, e, true);
    e.node.off("scroll-began", e._onScrollBegan, e, true);
    e.node.off("scroll-ended", e._onScrollEnded, e, true);
    e.node.off("scrolling", e._onScrolling, e, true);
    e.node.off(cc.Node.EventType.SIZE_CHANGED, e._onSizeChanged, e);
  };
  _creator.prototype._init = function () {
    var e = this;
    if (!e._inited) {
      e._scrollView = e.node.getComponent(cc.ScrollView);
      e.content = e._scrollView.content;
      if (e.content) {
        e._layout = e.content.getComponent(cc.Layout);
        e._align = e._layout.type;
        e._resizeMode = e._layout.resizeMode;
        e._startAxis = e._layout.startAxis;
        e._topGap = e._layout.paddingTop;
        e._rightGap = e._layout.paddingRight;
        e._bottomGap = e._layout.paddingBottom;
        e._leftGap = e._layout.paddingLeft;
        e._columnGap = e._layout.spacingX;
        e._lineGap = e._layout.spacingY;
        e._colLineNum;
        e._verticalDir = e._layout.verticalDirection;
        e._horizontalDir = e._layout.horizontalDirection;
        e.setTemplateItem(ResUtil.ResUtil.instantiate(e.templateType == c.PREFAB ? e.tmpPrefab : e.tmpNode));
        if (!(e._slideMode != s.ADHERING && e._slideMode != s.PAGE)) {
          e._scrollView.inertia = false;
          e._scrollView._onMouseWheel = function () {};
        }
        e.virtual || (e.lackCenter = false);
        e._lastDisplayData = [];
        e.displayData = [];
        e._pool = new cc.NodePool();
        e._forceUpdate = false;
        e._updateCounter = 0;
        e._updateDone = true;
        e.curPageNum = 0;
        if (e.cyclic) {
          e._scrollView._processAutoScrolling = this._processAutoScrolling.bind(e);
          e._scrollView._startBounceBackIfNeeded = function () {
            return false;
          };
        }
        switch (e._align) {
          case cc.Layout.Type.HORIZONTAL:
            switch (e._horizontalDir) {
              case cc.Layout.HorizontalDirection.LEFT_TO_RIGHT:
                e._alignCalcType = 1;
                break;
              case cc.Layout.HorizontalDirection.RIGHT_TO_LEFT:
                e._alignCalcType = 2;
            }
            break;
          case cc.Layout.Type.VERTICAL:
            switch (e._verticalDir) {
              case cc.Layout.VerticalDirection.TOP_TO_BOTTOM:
                e._alignCalcType = 3;
                break;
              case cc.Layout.VerticalDirection.BOTTOM_TO_TOP:
                e._alignCalcType = 4;
            }
            break;
          case cc.Layout.Type.GRID:
            switch (e._startAxis) {
              case cc.Layout.AxisDirection.HORIZONTAL:
                switch (e._verticalDir) {
                  case cc.Layout.VerticalDirection.TOP_TO_BOTTOM:
                    e._alignCalcType = 3;
                    break;
                  case cc.Layout.VerticalDirection.BOTTOM_TO_TOP:
                    e._alignCalcType = 4;
                }
                break;
              case cc.Layout.AxisDirection.VERTICAL:
                switch (e._horizontalDir) {
                  case cc.Layout.HorizontalDirection.LEFT_TO_RIGHT:
                    e._alignCalcType = 1;
                    break;
                  case cc.Layout.HorizontalDirection.RIGHT_TO_LEFT:
                    e._alignCalcType = 2;
                }
            }
        }
        ResUtil.ResUtil.removeAllChildren(e.content);
        e._inited = true;
      } else {
        cc.error(e.node.name + "'s cc.ScrollView unset content!");
      }
    }
  };
  _creator.prototype._processAutoScrolling = function (e) {
    this._scrollView._autoScrollAccumulatedTime += 1 * e;
    var t = Math.min(1, this._scrollView._autoScrollAccumulatedTime / this._scrollView._autoScrollTotalTime);
    if (this._scrollView._autoScrollAttenuate) {
      var o = t - 1;
      t = o * o * o * o * o + 1;
    }
    var n = this._scrollView._autoScrollStartPosition.add(this._scrollView._autoScrollTargetDelta.mul(t));
    var i = this._scrollView.getScrollEndedEventTiming();
    var a = Math.abs(t - 1) <= i;
    if (Math.abs(t - 1) <= this._scrollView.getScrollEndedEventTiming() && !this._scrollView._isScrollEndedWithThresholdEventFired) {
      this._scrollView._dispatchEvent("scroll-ended-with-threshold");
      this._scrollView._isScrollEndedWithThresholdEventFired = true;
    }
    a && (this._scrollView._autoScrolling = false);
    var r = n.sub(this._scrollView.getContentPosition());
    this._scrollView._moveContent(this._scrollView._clampDelta(r), a);
    this._scrollView._dispatchEvent("scrolling");
    if (!this._scrollView._autoScrolling) {
      this._scrollView._isBouncing = false;
      this._scrollView._scrolling = false;
      this._scrollView._dispatchEvent("scroll-ended");
    }
  };
  _creator.prototype.setTemplateItem = function (e) {
    if (e) {
      var t = this;
      t._itemTmp = e;
      if (t._resizeMode == cc.Layout.ResizeMode.CHILDREN) {
        t._itemSize = t._layout.cellSize;
      } else {
        t._itemSize = cc.size(e.width, e.height);
      }
      var o = e.getComponent(ListItem.default);
      var n = false;
      o || (n = true);
      n && (t.selectedMode = u.NONE);
      (o = e.getComponent(cc.Widget)) && o.enabled && (t._needUpdateWidget = true);
      t.selectedMode == u.MULT && (t.multSelected = []);
      switch (t._align) {
        case cc.Layout.Type.HORIZONTAL:
          t._colLineNum = 1;
          t._sizeType = false;
          break;
        case cc.Layout.Type.VERTICAL:
          t._colLineNum = 1;
          t._sizeType = true;
          break;
        case cc.Layout.Type.GRID:
          switch (t._startAxis) {
            case cc.Layout.AxisDirection.HORIZONTAL:
              var i = t.content.width - t._leftGap - t._rightGap;
              t._colLineNum = Math.floor((i + t._columnGap) / (t._itemSize.width + t._columnGap));
              t._sizeType = true;
              break;
            case cc.Layout.AxisDirection.VERTICAL:
              var a = t.content.height - t._topGap - t._bottomGap;
              t._colLineNum = Math.floor((a + t._lineGap) / (t._itemSize.height + t._lineGap));
              t._sizeType = false;
          }
      }
    }
  };
  _creator.prototype.checkInited = function (e) {
    undefined === e && (e = true);
    return !!this._inited || (e && cc.error("List initialization not completed!"), false);
  };
  _creator.prototype._resizeContent = function () {
    var e;
    var t = this;
    switch (t._align) {
      case cc.Layout.Type.HORIZONTAL:
        if (t._customSize) {
          var o = t._getFixedSize(null);
          e = t._leftGap + o.val + t._itemSize.width * (t._numItems - o.count) + t._columnGap * (t._numItems - 1) + t._rightGap;
        } else {
          e = t._leftGap + t._itemSize.width * t._numItems + t._columnGap * (t._numItems - 1) + t._rightGap;
        }
        break;
      case cc.Layout.Type.VERTICAL:
        if (t._customSize) {
          o = t._getFixedSize(null);
          e = t._topGap + o.val + t._itemSize.height * (t._numItems - o.count) + t._lineGap * (t._numItems - 1) + t._bottomGap;
        } else {
          e = t._topGap + t._itemSize.height * t._numItems + t._lineGap * (t._numItems - 1) + t._bottomGap;
        }
        break;
      case cc.Layout.Type.GRID:
        t.lackCenter && (t.lackCenter = false);
        switch (t._startAxis) {
          case cc.Layout.AxisDirection.HORIZONTAL:
            var n = Math.ceil(t._numItems / t._colLineNum);
            e = t._topGap + t._itemSize.height * n + t._lineGap * (n - 1) + t._bottomGap;
            break;
          case cc.Layout.AxisDirection.VERTICAL:
            var i = Math.ceil(t._numItems / t._colLineNum);
            e = t._leftGap + t._itemSize.width * i + t._columnGap * (i - 1) + t._rightGap;
        }
    }
    var a = t.content.getComponent(cc.Layout);
    a && (a.enabled = false);
    t._allItemSize = e;
    t._allItemSizeNoEdge = t._allItemSize - (t._sizeType ? t._topGap + t._bottomGap : t._leftGap + t._rightGap);
    if (t.cyclic) {
      var r = t._sizeType ? t.node.height : t.node.width;
      t._cyclicPos1 = 0;
      r -= t._cyclicPos1;
      t._cyclicNum = Math.ceil(r / t._allItemSizeNoEdge) + 1;
      var c = t._sizeType ? t._lineGap : t._columnGap;
      t._cyclicPos2 = t._cyclicPos1 + t._allItemSizeNoEdge + c;
      t._cyclicAllItemSize = t._allItemSize + t._allItemSizeNoEdge * (t._cyclicNum - 1) + c * (t._cyclicNum - 1);
      t._cycilcAllItemSizeNoEdge = t._allItemSizeNoEdge * t._cyclicNum;
      t._cycilcAllItemSizeNoEdge += c * (t._cyclicNum - 1);
    }
    t._lack = !t.cyclic && t._allItemSize < (t._sizeType ? t.node.height : t.node.width);
    var s = t._lack && t.lackCenter || !t.lackSlide ? .1 : 0;
    var u = t._lack ? (t._sizeType ? t.node.height : t.node.width) - s : t.cyclic ? t._cyclicAllItemSize : t._allItemSize;
    u < 0 && (u = 0);
    if (t._sizeType) {
      t.content.height = u;
    } else {
      t.content.width = u;
    }
  };
  _creator.prototype._onScrolling = function (e) {
    undefined === e && (e = null);
    null == this.frameCount && (this.frameCount = this._updateRate);
    if (!this._forceUpdate && e && "scroll-ended" != e.type && this.frameCount > 0) {
      this.frameCount--;
    } else {
      this.frameCount = this._updateRate;
      if (!this._aniDelRuning) {
        if (this.cyclic) {
          var t = this.content.getPosition();
          t = this._sizeType ? t.y : t.x;
          var o = this._allItemSizeNoEdge + (this._sizeType ? this._lineGap : this._columnGap);
          var n = this._sizeType ? cc.v2(0, o) : cc.v2(o, 0);
          switch (this._alignCalcType) {
            case 1:
              if (t > -this._cyclicPos1) {
                this.content.x = -this._cyclicPos2;
                this._scrollView.isAutoScrolling() && (this._scrollView._autoScrollStartPosition = this._scrollView._autoScrollStartPosition.sub(n));
              } else if (t < -this._cyclicPos2) {
                this.content.x = -this._cyclicPos1;
                this._scrollView.isAutoScrolling() && (this._scrollView._autoScrollStartPosition = this._scrollView._autoScrollStartPosition.add(n));
              }
              break;
            case 2:
              if (t < this._cyclicPos1) {
                this.content.x = this._cyclicPos2;
                this._scrollView.isAutoScrolling() && (this._scrollView._autoScrollStartPosition = this._scrollView._autoScrollStartPosition.add(n));
              } else if (t > this._cyclicPos2) {
                this.content.x = this._cyclicPos1;
                this._scrollView.isAutoScrolling() && (this._scrollView._autoScrollStartPosition = this._scrollView._autoScrollStartPosition.sub(n));
              }
              break;
            case 3:
              if (t < this._cyclicPos1) {
                this.content.y = this._cyclicPos2;
                this._scrollView.isAutoScrolling() && (this._scrollView._autoScrollStartPosition = this._scrollView._autoScrollStartPosition.add(n));
              } else if (t > this._cyclicPos2) {
                this.content.y = this._cyclicPos1;
                this._scrollView.isAutoScrolling() && (this._scrollView._autoScrollStartPosition = this._scrollView._autoScrollStartPosition.sub(n));
              }
              break;
            case 4:
              if (t > -this._cyclicPos1) {
                this.content.y = -this._cyclicPos2;
                this._scrollView.isAutoScrolling() && (this._scrollView._autoScrollStartPosition = this._scrollView._autoScrollStartPosition.sub(n));
              } else if (t < -this._cyclicPos2) {
                this.content.y = -this._cyclicPos1;
                this._scrollView.isAutoScrolling() && (this._scrollView._autoScrollStartPosition = this._scrollView._autoScrollStartPosition.add(n));
              }
          }
        }
        var i;
        var a;
        var r;
        var c;
        this._calcViewPos();
        if (this._sizeType) {
          i = this.viewTop;
          r = this.viewBottom;
        } else {
          a = this.viewRight;
          c = this.viewLeft;
        }
        if (this._virtual) {
          this.displayData = [];
          var s = undefined;
          var u = 0;
          var l = this._numItems - 1;
          if (this._customSize) {
            for (var d = false; u <= l && !d; u++) {
              s = this._calcItemPos(u);
              switch (this._align) {
                case cc.Layout.Type.HORIZONTAL:
                  if (s.right >= c && s.left <= a) {
                    this.displayData.push(s);
                  } else {
                    0 != u && this.displayData.length > 0 && (d = true);
                  }
                  break;
                case cc.Layout.Type.VERTICAL:
                  if (s.bottom <= i && s.top >= r) {
                    this.displayData.push(s);
                  } else {
                    0 != u && this.displayData.length > 0 && (d = true);
                  }
                  break;
                case cc.Layout.Type.GRID:
                  switch (this._startAxis) {
                    case cc.Layout.AxisDirection.HORIZONTAL:
                      if (s.bottom <= i && s.top >= r) {
                        this.displayData.push(s);
                      } else {
                        0 != u && this.displayData.length > 0 && (d = true);
                      }
                      break;
                    case cc.Layout.AxisDirection.VERTICAL:
                      if (s.right >= c && s.left <= a) {
                        this.displayData.push(s);
                      } else {
                        0 != u && this.displayData.length > 0 && (d = true);
                      }
                  }
              }
            }
          } else {
            var p = this._itemSize.width + this._columnGap;
            var h = this._itemSize.height + this._lineGap;
            switch (this._alignCalcType) {
              case 1:
                u = (c - this._leftGap) / p;
                l = (a - this._leftGap) / p;
                break;
              case 2:
                u = (-a - this._rightGap) / p;
                l = (-c - this._rightGap) / p;
                break;
              case 3:
                u = (-i - this._topGap) / h;
                l = (-r - this._topGap) / h;
                break;
              case 4:
                u = (r - this._bottomGap) / h;
                l = (i - this._bottomGap) / h;
            }
            u = Math.floor(u) * this._colLineNum;
            l = Math.ceil(l) * this._colLineNum;
            u < 0 && (u = 0);
            for (--l >= this._numItems && (l = this._numItems - 1); u <= l; u++) {
              this.displayData.push(this._calcItemPos(u));
            }
          }
          this._delRedundantItem();
          if (this.displayData.length <= 0 || !this._numItems) {
            return void (this._lastDisplayData = []);
          }
          this.firstListId = this.displayData[0].id;
          this.displayItemNum = this.displayData.length;
          var f = this._lastDisplayData.length;
          var g = this.displayItemNum != f;
          if (g) {
            this.frameByFrameRenderNum > 0 && this._lastDisplayData.sort(function (e, t) {
              return e - t;
            });
            g = this.firstListId != this._lastDisplayData[0] || this.displayData[this.displayItemNum - 1].id != this._lastDisplayData[f - 1];
          }
          if (this._forceUpdate || g) {
            if (this.frameByFrameRenderNum > 0) {
              if (this._numItems > 0) {
                if (this._updateDone) {
                  this._updateCounter = 0;
                } else {
                  this._doneAfterUpdate = true;
                }
                this._updateDone = false;
              } else {
                this._updateCounter = 0;
                this._updateDone = true;
              }
            } else {
              this._lastDisplayData = [];
              for (var _ = 0; _ < this.displayItemNum; _++) {
                this._createOrUpdateItem(this.displayData[_]);
              }
              this._forceUpdate = false;
            }
          }
          this._calcNearestItem();
        }
      }
    }
  };
  _creator.prototype._calcViewPos = function () {
    var e = this.content.getPosition();
    switch (this._alignCalcType) {
      case 1:
        this.elasticLeft = e.x > 0 ? e.x : 0;
        this.viewLeft = (e.x < 0 ? -e.x : 0) - this.elasticLeft;
        this.viewRight = this.viewLeft + this.node.width;
        this.elasticRight = this.viewRight > this.content.width ? Math.abs(this.viewRight - this.content.width) : 0;
        this.viewRight += this.elasticRight;
        break;
      case 2:
        this.elasticRight = e.x < 0 ? -e.x : 0;
        this.viewRight = (e.x > 0 ? -e.x : 0) + this.elasticRight;
        this.viewLeft = this.viewRight - this.node.width;
        this.elasticLeft = this.viewLeft < -this.content.width ? Math.abs(this.viewLeft + this.content.width) : 0;
        this.viewLeft -= this.elasticLeft;
        break;
      case 3:
        this.elasticTop = e.y < 0 ? Math.abs(e.y) : 0;
        this.viewTop = (e.y > 0 ? -e.y : 0) + this.elasticTop;
        this.viewBottom = this.viewTop - this.node.height;
        this.elasticBottom = this.viewBottom < -this.content.height ? Math.abs(this.viewBottom + this.content.height) : 0;
        this.viewBottom += this.elasticBottom;
        break;
      case 4:
        this.elasticBottom = e.y > 0 ? Math.abs(e.y) : 0;
        this.viewBottom = (e.y < 0 ? -e.y : 0) - this.elasticBottom;
        this.viewTop = this.viewBottom + this.node.height;
        this.elasticTop = this.viewTop > this.content.height ? Math.abs(this.viewTop - this.content.height) : 0;
        this.viewTop -= this.elasticTop;
    }
  };
  _creator.prototype._calcItemPos = function (e) {
    var t;
    var o;
    var n;
    var i;
    var a;
    var r;
    var c;
    var s;
    switch (this._align) {
      case cc.Layout.Type.HORIZONTAL:
        switch (this._horizontalDir) {
          case cc.Layout.HorizontalDirection.LEFT_TO_RIGHT:
            if (this._customSize) {
              var u = this._getFixedSize(e);
              a = this._leftGap + (this._itemSize.width + this._columnGap) * (e - u.count) + (u.val + this._columnGap * u.count);
              t = (l = this._customSize[e]) > 0 ? l : this._itemSize.width;
            } else {
              a = this._leftGap + (this._itemSize.width + this._columnGap) * e;
              t = this._itemSize.width;
            }
            if (this.lackCenter) {
              a -= this._leftGap;
              a += this.content.width / 2 - this._allItemSizeNoEdge / 2;
            }
            return {
              id: e,
              left: a,
              right: r = a + t,
              x: a + this._itemTmp.anchorX * t,
              y: this._itemTmp.y
            };
          case cc.Layout.HorizontalDirection.RIGHT_TO_LEFT:
            if (this._customSize) {
              u = this._getFixedSize(e);
              r = -this._rightGap - (this._itemSize.width + this._columnGap) * (e - u.count) - (u.val + this._columnGap * u.count);
              t = (l = this._customSize[e]) > 0 ? l : this._itemSize.width;
            } else {
              r = -this._rightGap - (this._itemSize.width + this._columnGap) * e;
              t = this._itemSize.width;
            }
            if (this.lackCenter) {
              r += this._rightGap;
              r -= this.content.width / 2 - this._allItemSizeNoEdge / 2;
            }
            return {
              id: e,
              right: r,
              left: a = r - t,
              x: a + this._itemTmp.anchorX * t,
              y: this._itemTmp.y
            };
        }
        break;
      case cc.Layout.Type.VERTICAL:
        switch (this._verticalDir) {
          case cc.Layout.VerticalDirection.TOP_TO_BOTTOM:
            if (this._customSize) {
              u = this._getFixedSize(e);
              n = -this._topGap - (this._itemSize.height + this._lineGap) * (e - u.count) - (u.val + this._lineGap * u.count);
              o = (l = this._customSize[e]) > 0 ? l : this._itemSize.height;
            } else {
              n = -this._topGap - (this._itemSize.height + this._lineGap) * e;
              o = this._itemSize.height;
            }
            if (this.lackCenter) {
              n += this._topGap;
              n -= this.content.height / 2 - this._allItemSizeNoEdge / 2;
            }
            return {
              id: e,
              top: n,
              bottom: i = n - o,
              x: this._itemTmp.x,
              y: i + this._itemTmp.anchorY * o
            };
          case cc.Layout.VerticalDirection.BOTTOM_TO_TOP:
            var l;
            if (this._customSize) {
              u = this._getFixedSize(e);
              i = this._bottomGap + (this._itemSize.height + this._lineGap) * (e - u.count) + (u.val + this._lineGap * u.count);
              o = (l = this._customSize[e]) > 0 ? l : this._itemSize.height;
            } else {
              i = this._bottomGap + (this._itemSize.height + this._lineGap) * e;
              o = this._itemSize.height;
            }
            if (this.lackCenter) {
              i -= this._bottomGap;
              i += this.content.height / 2 - this._allItemSizeNoEdge / 2;
            }
            return {
              id: e,
              top: n = i + o,
              bottom: i,
              x: this._itemTmp.x,
              y: i + this._itemTmp.anchorY * o
            };
        }
      case cc.Layout.Type.GRID:
        var d = Math.floor(e / this._colLineNum);
        switch (this._startAxis) {
          case cc.Layout.AxisDirection.HORIZONTAL:
            switch (this._verticalDir) {
              case cc.Layout.VerticalDirection.TOP_TO_BOTTOM:
                s = (i = (n = -this._topGap - (this._itemSize.height + this._lineGap) * d) - this._itemSize.height) + this._itemTmp.anchorY * this._itemSize.height;
                break;
              case cc.Layout.VerticalDirection.BOTTOM_TO_TOP:
                n = (i = this._bottomGap + (this._itemSize.height + this._lineGap) * d) + this._itemSize.height;
                s = i + this._itemTmp.anchorY * this._itemSize.height;
            }
            c = this._leftGap + e % this._colLineNum * (this._itemSize.width + this._columnGap);
            switch (this._horizontalDir) {
              case cc.Layout.HorizontalDirection.LEFT_TO_RIGHT:
                c += this._itemTmp.anchorX * this._itemSize.width;
                c -= this.content.anchorX * this.content.width;
                break;
              case cc.Layout.HorizontalDirection.RIGHT_TO_LEFT:
                c += (1 - this._itemTmp.anchorX) * this._itemSize.width;
                c -= (1 - this.content.anchorX) * this.content.width;
                c *= -1;
            }
            return {
              id: e,
              top: n,
              bottom: i,
              x: c,
              y: s
            };
          case cc.Layout.AxisDirection.VERTICAL:
            switch (this._horizontalDir) {
              case cc.Layout.HorizontalDirection.LEFT_TO_RIGHT:
                r = (a = this._leftGap + (this._itemSize.width + this._columnGap) * d) + this._itemSize.width;
                c = a + this._itemTmp.anchorX * this._itemSize.width;
                c -= this.content.anchorX * this.content.width;
                break;
              case cc.Layout.HorizontalDirection.RIGHT_TO_LEFT:
                c = (a = (r = -this._rightGap - (this._itemSize.width + this._columnGap) * d) - this._itemSize.width) + this._itemTmp.anchorX * this._itemSize.width;
                c += (1 - this.content.anchorX) * this.content.width;
            }
            s = -this._topGap - e % this._colLineNum * (this._itemSize.height + this._lineGap);
            switch (this._verticalDir) {
              case cc.Layout.VerticalDirection.TOP_TO_BOTTOM:
                s -= (1 - this._itemTmp.anchorY) * this._itemSize.height;
                s += (1 - this.content.anchorY) * this.content.height;
                break;
              case cc.Layout.VerticalDirection.BOTTOM_TO_TOP:
                s -= this._itemTmp.anchorY * this._itemSize.height;
                s += this.content.anchorY * this.content.height;
                s *= -1;
            }
            return {
              id: e,
              left: a,
              right: r,
              x: c,
              y: s
            };
        }
    }
  };
  _creator.prototype._calcExistItemPos = function (e) {
    var t = this.getItemByListId(e);
    if (!t) {
      return null;
    }
    var o = {
      id: e,
      x: t.x,
      y: t.y
    };
    if (this._sizeType) {
      o.top = t.y + t.height * (1 - t.anchorY);
      o.bottom = t.y - t.height * t.anchorY;
    } else {
      o.left = t.x - t.width * t.anchorX;
      o.right = t.x + t.width * (1 - t.anchorX);
    }
    return o;
  };
  _creator.prototype.getItemPos = function (e) {
    if (this._virtual || this.frameByFrameRenderNum) {
      return this._calcItemPos(e);
    } else {
      return this._calcExistItemPos(e);
    }
  };
  _creator.prototype._getFixedSize = function (e) {
    if (!this._customSize) {
      return null;
    }
    null == e && (e = this._numItems);
    var t = 0;
    var o = 0;
    for (var n in this._customSize) if (parseInt(n) < e) {
      t += this._customSize[n];
      o++;
    }
    return {
      val: t,
      count: o
    };
  };
  _creator.prototype._onScrollBegan = function () {
    this._beganPos = this._sizeType ? this.viewTop : this.viewLeft;
  };
  _creator.prototype._onScrollEnded = function () {
    var e = this;
    e.curScrollIsTouch = false;
    if (null != e.scrollToListId) {
      var t = e.getItemByListId(e.scrollToListId);
      e.scrollToListId = null;
      t && cc.tween(t).to(.1, {
        scale: 1.06
      }).to(.1, {
        scale: 1
      }).start();
    }
    e._onScrolling();
    if (e._slideMode != s.ADHERING || e.adhering) {
      if (e._slideMode == s.PAGE) {
        if (null != e._beganPos && e.curScrollIsTouch) {
          this._pageAdhere();
        } else {
          e.adhere();
        }
      }
    } else {
      e.adhere();
    }
  };
  _creator.prototype._onTouchStart = function (e, t) {
    if (!this._scrollView.hasNestedViewGroup(e, t) && (this.curScrollIsTouch = true, e.eventPhase !== cc.Event.AT_TARGET || e.target !== this.node)) {
      for (var o = e.target; null == o._listId && o.parent;) {
        o = o.parent;
      }
      this._scrollItem = null != o._listId ? o : e.target;
    }
  };
  _creator.prototype._onTouchUp = function () {
    var e = this;
    e._scrollPos = null;
    if (e._slideMode == s.ADHERING) {
      this.adhering && (this._adheringBarrier = true);
      e.adhere();
    } else if (e._slideMode == s.PAGE) {
      if (null != e._beganPos) {
        this._pageAdhere();
      } else {
        e.adhere();
      }
    }
    this._scrollItem = null;
  };
  _creator.prototype._onTouchCancelled = function (e, t) {
    var o = this;
    if (!(o._scrollView.hasNestedViewGroup(e, t) || e.simulate)) {
      o._scrollPos = null;
      if (o._slideMode == s.ADHERING) {
        o.adhering && (o._adheringBarrier = true);
        o.adhere();
      } else if (o._slideMode == s.PAGE) {
        if (null != o._beganPos) {
          o._pageAdhere();
        } else {
          o.adhere();
        }
      }
      this._scrollItem = null;
    }
  };
  _creator.prototype._onSizeChanged = function () {
    this.checkInited(false) && this._onScrolling();
  };
  _creator.prototype._onItemAdaptive = function (e) {
    if (!this._sizeType && e.width != this._itemSize.width || this._sizeType && e.height != this._itemSize.height) {
      this._customSize || (this._customSize = {});
      var t = this._sizeType ? e.height : e.width;
      if (this._customSize[e._listId] != t) {
        this._customSize[e._listId] = t;
        this._resizeContent();
        this.updateAll();
        if (null != this._scrollToListId) {
          this._scrollPos = null;
          this.unschedule(this._scrollToSo);
          this.scrollTo(this._scrollToListId, Math.max(0, this._scrollToEndTime - new Date().getTime() / 1e3));
        }
      }
    }
  };
  _creator.prototype._pageAdhere = function () {
    var e = this;
    if (e.cyclic || !(e.elasticTop > 0 || e.elasticRight > 0 || e.elasticBottom > 0 || e.elasticLeft > 0)) {
      var t = e._sizeType ? e.viewTop : e.viewLeft;
      var o = (e._sizeType ? e.node.height : e.node.width) * e.pageDistance;
      if (Math.abs(e._beganPos - t) > o) {
        switch (e._alignCalcType) {
          case 1:
          case 4:
            if (e._beganPos > t) {
              e.prePage(.5);
            } else {
              e.nextPage(.5);
            }
            break;
          case 2:
          case 3:
            if (e._beganPos < t) {
              e.prePage(.5);
            } else {
              e.nextPage(.5);
            }
        }
      } else {
        e.elasticTop <= 0 && e.elasticRight <= 0 && e.elasticBottom <= 0 && e.elasticLeft <= 0 && e.adhere();
      }
      e._beganPos = null;
    }
  };
  _creator.prototype.adhere = function () {
    var e = this;
    if (e.checkInited() && !(e.elasticTop > 0 || e.elasticRight > 0 || e.elasticBottom > 0 || e.elasticLeft > 0)) {
      e.adhering = true;
      e._calcNearestItem();
      var t = (e._sizeType ? e._topGap : e._leftGap) / (e._sizeType ? e.node.height : e.node.width);
      e.scrollTo(e.nearestListId, .7, t);
    }
  };
  _creator.prototype.update = function () {
    if (!(this.frameByFrameRenderNum <= 0 || this._updateDone)) {
      if (this._virtual) {
        var e = this._updateCounter + this.frameByFrameRenderNum > this.displayItemNum ? this.displayItemNum : this._updateCounter + this.frameByFrameRenderNum;
        for (var t = this._updateCounter; t < e; t++) {
          var o = this.displayData[t];
          o && this._createOrUpdateItem(o);
        }
        if (this._updateCounter >= this.displayItemNum - 1) {
          if (this._doneAfterUpdate) {
            this._updateCounter = 0;
            this._updateDone = false;
            this._doneAfterUpdate = false;
          } else {
            this._updateDone = true;
            this._delRedundantItem();
            this._forceUpdate = false;
            this._calcNearestItem();
            this.slideMode == s.PAGE && (this.curPageNum = this.nearestListId);
          }
        } else {
          this._updateCounter += this.frameByFrameRenderNum;
        }
      } else if (this._updateCounter < this._numItems) {
        e = this._updateCounter + this.frameByFrameRenderNum > this._numItems ? this._numItems : this._updateCounter + this.frameByFrameRenderNum;
        for (t = this._updateCounter; t < e; t++) {
          this._createOrUpdateItem2(t);
        }
        this._updateCounter += this.frameByFrameRenderNum;
      } else {
        this._updateDone = true;
        this._calcNearestItem();
        this.slideMode == s.PAGE && (this.curPageNum = this.nearestListId);
      }
    }
  };
  _creator.prototype._createOrUpdateItem = function (e) {
    var t = this.getItemByListId(e.id);
    if (t) {
      if (this._forceUpdate && this.renderEvent) {
        t.setPosition(cc.v2(e.x, e.y));
        this._resetItemSize(t);
        this.renderEvent && cc.Component.EventHandler.emitEvents([this.renderEvent], t, e.id % this._actualNumItems);
      }
    } else {
      var o = this._pool.size() > 0;
      t = o ? this._pool.get() : ResUtil.ResUtil.instantiate(this._itemTmp);
      if (!(o && cc.isValid(t))) {
        t = ResUtil.ResUtil.instantiate(this._itemTmp);
        o = false;
      }
      if (t._listId != e.id) {
        t._listId = e.id;
        t.setContentSize(this._itemSize);
      }
      t.setPosition(cc.v2(e.x, e.y));
      this._resetItemSize(t);
      this.content.addChild(t);
      if (o && this._needUpdateWidget) {
        var n = t.getComponent(cc.Widget);
        n && n.updateAlignment();
      }
      t.setSiblingIndex(this.content.childrenCount - 1);
      var i = t.getComponent(ListItem.default);
      t.listItem = i;
      if (i) {
        i.listId = e.id;
        i.list = this;
        i._registerEvent();
      }
      this.renderEvent && cc.Component.EventHandler.emitEvents([this.renderEvent], t, e.id % this._actualNumItems);
    }
    this._resetItemSize(t);
    this._updateListItem(t.listItem);
    this._lastDisplayData.indexOf(e.id) < 0 && this._lastDisplayData.push(e.id);
  };
  _creator.prototype._createOrUpdateItem2 = function (e) {
    var t;
    var o = this.content.children[e];
    if (o) {
      if (this._forceUpdate && this.renderEvent) {
        o._listId = e;
        t && (t.listId = e);
        this.renderEvent && cc.Component.EventHandler.emitEvents([this.renderEvent], o, e % this._actualNumItems);
      }
    } else {
      (o = ResUtil.ResUtil.instantiate(this._itemTmp))._listId = e;
      this.content.addChild(o);
      t = o.getComponent(ListItem.default);
      o.listItem = t;
      if (t) {
        t.listId = e;
        t.list = this;
        t._registerEvent();
      }
      this.renderEvent && cc.Component.EventHandler.emitEvents([this.renderEvent], o, e % this._actualNumItems);
    }
    this._updateListItem(t);
    this._lastDisplayData.indexOf(e) < 0 && this._lastDisplayData.push(e);
  };
  _creator.prototype._updateListItem = function (e) {
    if (e && this.selectedMode > u.NONE) {
      var t = e.node;
      switch (this.selectedMode) {
        case u.SINGLE:
          e.selected = this.selectedId == t._listId;
          break;
        case u.MULT:
          e.selected = this.multSelected.indexOf(t._listId) >= 0;
      }
    }
  };
  _creator.prototype._resetItemSize = function () {};
  _creator.prototype._updateItemPos = function (e) {
    var t = isNaN(e) ? e : this.getItemByListId(e);
    var o = this.getItemPos(t._listId);
    t.setPosition(o.x, o.y);
  };
  _creator.prototype.setMultSelected = function (e, t) {
    var o = this;
    if (o.checkInited()) {
      Array.isArray(e) || (e = [e]);
      if (null == t) {
        o.multSelected = e;
      } else {
        var n = undefined;
        var i = undefined;
        if (t) {
          for (var a = e.length - 1; a >= 0; a--) {
            n = e[a];
            (i = o.multSelected.indexOf(n)) < 0 && o.multSelected.push(n);
          }
        } else {
          for (a = e.length - 1; a >= 0; a--) {
            n = e[a];
            (i = o.multSelected.indexOf(n)) >= 0 && o.multSelected.splice(i, 1);
          }
        }
      }
      o._forceUpdate = true;
      o._onScrolling();
    }
  };
  _creator.prototype.getMultSelected = function () {
    return this.multSelected;
  };
  _creator.prototype.hasMultSelected = function (e) {
    return this.multSelected && this.multSelected.indexOf(e) >= 0;
  };
  _creator.prototype.updateItem = function (e) {
    if (this.checkInited()) {
      Array.isArray(e) || (e = [e]);
      var t = 0;
      for (var o = e.length; t < o; t++) {
        var n = e[t];
        var i = this.getItemByListId(n);
        i && cc.Component.EventHandler.emitEvents([this.renderEvent], i, n % this._actualNumItems);
      }
    }
  };
  _creator.prototype.updateAll = function () {
    this.checkInited() && (this.numItems = this.numItems);
  };
  _creator.prototype.getItemByListId = function (e) {
    if (this.content) {
      for (var t = this.content.childrenCount - 1; t >= 0; t--) {
        var o = this.content.children[t];
        if (o._listId == e) {
          return o;
        }
      }
    }
  };
  _creator.prototype._getOutsideItem = function () {
    var e;
    var t = [];
    for (var o = this.content.childrenCount - 1; o >= 0; o--) {
      e = this.content.children[o];
      this.displayData.find(function (t) {
        return t.id == e._listId;
      }) || t.push(e);
    }
    return t;
  };
  _creator.prototype._delRedundantItem = function () {
    if (this._virtual) {
      var e = this._getOutsideItem();
      for (var t = e.length - 1; t >= 0; t--) {
        var o = e[t];
        if (!this._scrollItem || o._listId != this._scrollItem._listId) {
          o.isCached = true;
          this._pool.put(o);
          for (var n = this._lastDisplayData.length - 1; n >= 0; n--) {
            if (this._lastDisplayData[n] == o._listId) {
              this._lastDisplayData.splice(n, 1);
              break;
            }
          }
        }
      }
    } else {
      for (; this.content.childrenCount > this._numItems;) {
        this._delSingleItem(this.content.children[this.content.childrenCount - 1]);
      }
    }
  };
  _creator.prototype._delSingleItem = function (e) {
    ResUtil.ResUtil.removeFromParent(e);
    e.destroy && e.destroy();
    e = null;
  };
  _creator.prototype.aniDelItem = function (e, t, o) {
    var n = this;
    if (!n.checkInited() || n.cyclic || !n._virtual) {
      return cc.error("This function is not allowed to be called!");
    }
    if (!t) {
      return cc.error("CallFunc are not allowed to be NULL, You need to delete the corresponding index in the data array in the CallFunc!");
    }
    if (n._aniDelRuning) {
      return cc.warn("Please wait for the current deletion to finish!");
    }
    var i;
    var a = n.getItemByListId(e);
    if (a) {
      i = a.getComponent(ListItem.default);
      n._aniDelRuning = true;
      n._aniDelCB = t;
      n._aniDelItem = a;
      n._aniDelBeforePos = a.position;
      n._aniDelBeforeScale = a.scale;
      var r = n.displayData[n.displayData.length - 1].id;
      var c = i.selected;
      i.showAni(o, function () {
        var o;
        var i;
        var s;
        r < n._numItems - 2 && (o = r + 1);
        if (null != o) {
          var l = n._calcItemPos(o);
          n.displayData.push(l);
          if (n._virtual) {
            n._createOrUpdateItem(l);
          } else {
            n._createOrUpdateItem2(o);
          }
        } else {
          n._numItems--;
        }
        if (n.selectedMode == u.SINGLE) {
          if (c) {
            n._selectedId = -1;
          } else {
            n._selectedId - 1 >= 0 && n._selectedId--;
          }
        } else if (n.selectedMode == u.MULT && n.multSelected.length) {
          var d = n.multSelected.indexOf(e);
          d >= 0 && n.multSelected.splice(d, 1);
          for (var p = n.multSelected.length - 1; p >= 0; p--) {
            (g = n.multSelected[p]) >= e && n.multSelected[p]--;
          }
        }
        if (n._customSize) {
          n._customSize[e] && delete n._customSize[e];
          var h = {};
          var f = undefined;
          for (var g in n._customSize) {
            f = n._customSize[g];
            var _ = parseInt(g);
            h[_ - (_ >= e ? 1 : 0)] = f;
          }
          n._customSize = h;
        }
        for (p = null != o ? o : r; p >= e + 1; p--) {
          if (a = n.getItemByListId(p)) {
            var m = n._calcItemPos(p - 1);
            i = cc.tween(a).to(.2333, {
              position: cc.v2(m.x, m.y)
            });
            if (p <= e + 1) {
              s = true;
              i.call(function () {
                n._aniDelRuning = false;
                t(e);
                delete n._aniDelCB;
              });
            }
            i.start();
          }
        }
        if (!s) {
          n._aniDelRuning = false;
          t(e);
          n._aniDelCB = null;
        }
      }, true);
    } else {
      t(e);
    }
  };
  _creator.prototype.scrollTo = function (e, t, o, n) {
    undefined === t && (t = .5);
    undefined === o && (o = null);
    undefined === n && (n = false);
    var i = this;
    if (i.checkInited(false)) {
      if (null == t) {
        t = .5;
      } else {
        t < 0 && (t = 0);
      }
      if (e < 0) {
        e = 0;
      } else {
        e >= i._numItems && (e = i._numItems - 1);
      }
      !i._virtual && i._layout && i._layout.enabled && i._layout.updateLayout();
      var a;
      var r;
      var c = i.getItemPos(e);
      if (!c) {
        return false;
      }
      switch (i._alignCalcType) {
        case 1:
          a = c.left;
          a -= null != o ? i.node.width * o : i._leftGap;
          c = cc.v2(a, 0);
          break;
        case 2:
          a = c.right - i.node.width;
          a += null != o ? i.node.width * o : i._rightGap;
          c = cc.v2(a + i.content.width, 0);
          break;
        case 3:
          r = c.top;
          r += null != o ? i.node.height * o : i._topGap;
          c = cc.v2(0, -r);
          break;
        case 4:
          r = c.bottom + i.node.height;
          r -= null != o ? i.node.height * o : i._bottomGap;
          c = cc.v2(0, -r + i.content.height);
      }
      var s = i.content.getPosition();
      s = Math.abs(i._sizeType ? s.y : s.x);
      var u = i._sizeType ? c.y : c.x;
      if (Math.abs((null != i._scrollPos ? i._scrollPos : s) - u) > .5) {
        i._scrollView.scrollToOffset(c, t);
        i._scrollToListId = e;
        i._scrollToEndTime = new Date().getTime() / 1e3 + t;
        i._scrollToSo = i.scheduleOnce(function () {
          i._adheringBarrier || (i.adhering = i._adheringBarrier = false);
          i._scrollPos = i._scrollToListId = i._scrollToEndTime = i._scrollToSo = null;
          if (n) {
            var t = i.getItemByListId(e);
            t && cc.tween(t).to(.1, {
              scale: 1.05
            }).to(.1, {
              scale: 1
            }).start();
          }
        }, t + .1);
        t <= 0 && i._onScrolling();
      }
    }
  };
  _creator.prototype._calcNearestItem = function () {
    var e;
    var t;
    var o;
    var n;
    var i;
    var a;
    var r = this;
    r.nearestListId = null;
    r._virtual && r._calcViewPos();
    o = r.viewTop;
    n = r.viewRight;
    i = r.viewBottom;
    a = r.viewLeft;
    var c = false;
    for (var s = 0; s < r.content.childrenCount && !c; s += r._colLineNum) {
      if (e = r._virtual ? r.displayData[s] : r._calcExistItemPos(s)) {
        t = r._sizeType ? (e.top + e.bottom) / 2 : t = (e.left + e.right) / 2;
        switch (r._alignCalcType) {
          case 1:
            if (e.right >= a) {
              r.nearestListId = e.id;
              a > t && (r.nearestListId += r._colLineNum);
              c = true;
            }
            break;
          case 2:
            if (e.left <= n) {
              r.nearestListId = e.id;
              n < t && (r.nearestListId += r._colLineNum);
              c = true;
            }
            break;
          case 3:
            if (e.bottom <= o) {
              r.nearestListId = e.id;
              o < t && (r.nearestListId += r._colLineNum);
              c = true;
            }
            break;
          case 4:
            if (e.top >= i) {
              r.nearestListId = e.id;
              i > t && (r.nearestListId += r._colLineNum);
              c = true;
            }
        }
      }
    }
    if ((e = r._virtual ? r.displayData[r.displayItemNum - 1] : r._calcExistItemPos(r._numItems - 1)) && e.id == r._numItems - 1) {
      t = r._sizeType ? (e.top + e.bottom) / 2 : t = (e.left + e.right) / 2;
      switch (r._alignCalcType) {
        case 1:
          n > t && (r.nearestListId = e.id);
          break;
        case 2:
          a < t && (r.nearestListId = e.id);
          break;
        case 3:
          i < t && (r.nearestListId = e.id);
          break;
        case 4:
          o > t && (r.nearestListId = e.id);
      }
    }
  };
  _creator.prototype.prePage = function (e) {
    undefined === e && (e = .5);
    this.checkInited() && this.skipPage(this.curPageNum - 1, e);
  };
  _creator.prototype.nextPage = function (e) {
    undefined === e && (e = .5);
    this.checkInited() && this.skipPage(this.curPageNum + 1, e);
  };
  _creator.prototype.skipPage = function (e, t) {
    var o = this;
    if (o.checkInited()) {
      if (o._slideMode != s.PAGE) {
        return cc.error("This function is not allowed to be called, Must SlideMode = PAGE!");
      } else {
        return void (e < 0 || e >= o._numItems || o.curPageNum != e && (o.curPageNum = e, o.pageChangeEvent && cc.Component.EventHandler.emitEvents([o.pageChangeEvent], e), o.scrollTo(e, t)));
      }
    }
  };
  _creator.prototype.calcCustomSize = function (e) {
    var t = this;
    if (t.checkInited()) {
      if (!t._itemTmp) {
        return cc.error("Unset template item!");
      }
      if (!t.renderEvent) {
        return cc.error("Unset Render-Event!");
      }
      t._customSize = {};
      var o = ResUtil.ResUtil.instantiate(t._itemTmp);
      t.content.addChild(o);
      for (var n = 0; n < e; n++) {
        cc.Component.EventHandler.emitEvents([t.renderEvent], o, n);
        o.height == t._itemSize.height && o.width == t._itemSize.width || (t._customSize[n] = t._sizeType ? o.height : o.width);
      }
      Object.keys(t._customSize).length || (t._customSize = null);
      ResUtil.ResUtil.removeFromParent(o);
      o.destroy && o.destroy();
      return t._customSize;
    }
  };
  __decorate([_property({
    type: cc.Enum(c),
    // tooltip: false
  })], _creator.prototype, "templateType", undefined);
  __decorate([_property({
    type: cc.Node,
    // tooltip: false,
    visible: function () {
      return this.templateType == c.NODE;
    }
  })], _creator.prototype, "tmpNode", undefined);
  __decorate([_property({
    type: cc.Prefab,
    // tooltip: false,
    visible: function () {
      return this.templateType == c.PREFAB;
    }
  })], _creator.prototype, "tmpPrefab", undefined);
  __decorate([_property()], _creator.prototype, "_slideMode", undefined);
  __decorate([_property({
    type: cc.Enum(s),
    // tooltip: false
  })], _creator.prototype, "slideMode", null);
  __decorate([_property({
    type: cc.Float,
    range: [0, 1, .1],
    // tooltip: false,
    slide: true,
    visible: function () {
      return this._slideMode == s.PAGE;
    }
  })], _creator.prototype, "pageDistance", undefined);
  __decorate([_property({
    type: cc.Component.EventHandler,
    // tooltip: false,
    visible: function () {
      return this._slideMode == s.PAGE;
    }
  })], _creator.prototype, "pageChangeEvent", undefined);
  __decorate([_property()], _creator.prototype, "_virtual", undefined);
  __decorate([_property({
    type: cc.Boolean,
    // tooltip: false
  })], _creator.prototype, "virtual", null);
  __decorate([_property({
    // tooltip: false,
    visible: function () {
      var e = this.slideMode == s.NORMAL;
      e || (this.cyclic = false);
      return e;
    }
  })], _creator.prototype, "cyclic", undefined);
  __decorate([_property({
    // tooltip: false,
    visible: function () {
      return this.virtual;
    }
  })], _creator.prototype, "lackCenter", undefined);
  __decorate([_property({
    // tooltip: false,
    visible: function () {
      var e = this.virtual && !this.lackCenter;
      e || (this.lackSlide = false);
      return e;
    }
  })], _creator.prototype, "lackSlide", undefined);
  __decorate([_property({
    type: cc.Integer
  })], _creator.prototype, "_updateRate", undefined);
  __decorate([_property({
    type: cc.Integer,
    range: [0, 6, 1],
    // tooltip: false,
    slide: true
  })], _creator.prototype, "updateRate", null);
  __decorate([_property({
    type: cc.Integer,
    range: [0, 12, 1],
    // tooltip: false,
    slide: true
  })], _creator.prototype, "frameByFrameRenderNum", undefined);
  __decorate([_property({
    type: cc.Component.EventHandler,
    // tooltip: false
  })], _creator.prototype, "renderEvent", undefined);
  __decorate([_property({
    type: cc.Enum(u),
    // tooltip: false
  })], _creator.prototype, "selectedMode", undefined);
  __decorate([_property({
    // tooltip: false,
    visible: function () {
      return this.selectedMode == u.SINGLE;
    }
  })], _creator.prototype, "repeatEventSingle", undefined);
  __decorate([_property({
    type: cc.Component.EventHandler,
    // tooltip: false,
    visible: function () {
      return this.selectedMode > u.NONE;
    }
  })], _creator.prototype, "selectedEvent", undefined);
  __decorate([_property({
    serializable: false
  })], _creator.prototype, "_numItems", undefined);
  return __decorate([_ccclass, h(), _menu("UI组件/List Extent"), _(cc.ScrollView), _executionOrder(-5e3)], _creator);
}(cc.Component);
exports.default = _def_List;